<?php
namespace app\api\controller;
use think\Controller;
use think\facade\Cookie;
use think\facade\Session;
use think\facade\Url;
use services\OpensslService;
class Base extends Controller{
    public $return_data=['Code'=>1,'Msg'=>'','ErrorSql'=>'','Data'=>[]];
    public $AccountInfo=[];
    public function initialize(){
        /*
        $token = $this->request->param('token');
        if (!$token) {
            echo json_encode(['Code'=>-1,'Msg'=>'不合法的请求']);exit;
        }
        $opensslService = new OpensslService();
        $decJson=$opensslService->aes_decrypt($token);
        if(!$decJson) {
            echo json_encode(['Code'=>-1,'Msg'=>'token异常,请重新登录']);exit;
        }

        $this->AccountInfo = $tokenInfo = json_decode($decJson,1);
        if(!isset($tokenInfo['created_at'])) {
            echo json_encode(['Code'=>-1,'Msg'=>'token异常,请重新登录']);exit;
        }

        $exptime=$tokenInfo['created_at']+3600 * 24;
        if($exptime < now_time()) {
            echo json_encode(['Code'=>-1,'Msg'=>'帐号已过期,请重新登录']);exit;
        }
      */
    }

    public function print_result($return_data){
        if(!is_array($return_data)){
            $return_data['Code']=0;
            $return_data['Msg']='输出信息不符合规范';
        }
        return json($return_data)->code(200)->header(['Content-Type' => 'application/json']);
    }

    /**
     * 检查必填项参数是否为空
     */
    public function checkInputDataIsEmpty($input, $indexArr)
    {
        foreach($indexArr as $v){
            if(!isset($input[$v]) || (empty($input[$v]) && ($input[$v] != 0 || $input[$v] != false))){
                return $v;
            }
        }
        return '';
    }

}
